const path = require("path");
const fs = require("fs");

const pathStr = path.join('/a', '/b/c', '../', 'd')

console.log(pathStr) // /a/b/d

fs.readFile(path.join(__dirname, "./text.txt"), "utf-8", (err, dataStr) => {
  if (err) {
    return console.log("读取文件失败！" + err.message);
  }else{
    console.log("读取文件成功！" + dataStr);
  }
});

const fPath = "./a/b/c/d.txt";

const fullName = path.basename(fPath); // 获取文件名

console.log(fullName);

const fullName1 = path.basename(fPath, ".txt"); // 获取文件名
console.log(fullName1);

const extName = path.extname(fPath); // 获取文件扩展名

console.log(extName);

const dirName = path.dirname(fPath); // 获取文件所在目录

console.log(dirName);
